import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)// 通过Vue.use引入了Vuex

// 通过一个 new Vuex.Store 的方式,创建了一个Vuex的实例。
export default new Vuex.Store({

  // state: {
  // },
  state () {
    return {
      loginStatus: '用户已经登录',
      count: 0
    }
  },
  getters: {
    len (state) {
      console.log('getters执行了')
      return state.loginStatus.length
    }
  },
  mutations: {
    changeCount(state, num) {
      state.count += num
      console.log('mutation执行了，count值为', state.count)
    }
  },
  actions: {
    delayChangeCount (store, num) {
      setTimeout(() => {
        store.commit('changeCount', num)
      }, 2000)
    }
  },
  modules: {
    modA: {
      state () {
        return {
          aloginStatus: 'aaa用户已经登录'
        }
      },
      mutations: {
        changeCount(state, num) {
          state.count += num
          console.log('amutation执行了，count值为', state.count)
        }
      }
    }
  }
})
